package base2dev.web.common;

import javax.persistence.EntityManager;

import org.apache.wicket.Page;
import org.apache.wicket.Request;
import org.apache.wicket.RequestCycle;
import org.apache.wicket.Response;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.apache.wicket.util.io.IObjectStreamFactory;
import org.apache.wicket.util.lang.Objects;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.orm.jpa.EntityManagerFactoryInfo;

import base2dev.web.pages.Home;
import base2dev.web.pages.musics.AlbumPage;
import base2dev.web.pages.musics.Albums;
import base2dev.web.pages.musics.ArtistPage;
import base2dev.web.pages.musics.Artists;
import base2dev.web.pages.musics.SongPage;
import base2dev.web.pages.musics.crud.ArtistList;
import base2dev.web.pages.to_delete.data.CreateDefaultData;
import base2dev.web.pages.to_delete.test.BasicControls;

public class Application extends WebApplication implements
		ApplicationContextAware {

	@SuppressWarnings("unused")
	private ApplicationContext applicationContext;

	@Override
	public Class<? extends Page> getHomePage() {
		return Home.class;
	}

	private EntityManager em;
	
	
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.applicationContext = applicationContext;
		
	}

	@Override
	protected void init() {

		Objects
				.setObjectStreamFactory(new IObjectStreamFactory.DefaultObjectStreamFactory());

		getDebugSettings().setAjaxDebugModeEnabled(false);
		getMarkupSettings().setStripWicketTags(true);
		getResourceSettings().setThrowExceptionOnMissingResource(false);

		mountBookmarkablePage("/home", Home.class);
		mountBookmarkablePage("/artist", ArtistPage.class);
		mountBookmarkablePage("/album", AlbumPage.class);
		mountBookmarkablePage("/song", SongPage.class);
		mountBookmarkablePage("/artists", Artists.class);
		mountBookmarkablePage("/albums", Albums.class);
		 
		
		mountBookmarkablePage("/manageArtist", ArtistList.class);
		
		
		mountBookmarkablePage("/test/basicControls", BasicControls.class);
		mountBookmarkablePage("/defaultData", CreateDefaultData.class);

		addComponentInstantiationListener(new SpringComponentInjector(this));

	}

//	@Override
//	public RequestCycle newRequestCycle(Request request, Response response) {
//		return new WebRequestCycle(this, (WebRequest) request, response);
//	}
}
